/* Autostop
 *
 * Copyright (c) Maciej Gajewski, Grzegorz Latarowski
 * http://code.google.com/p/autostop-automaty-drogowe
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
 */

#include "serverthread.h"

// ================================== constructor =============================
ServerThread::ServerThread( int socket, QObject* parent ) : QThread( parent ), _socket( socket )
{
	// nope
}

// ================================== destructor =============================
ServerThread::~ServerThread()
{
	// nope
}

// ================================== run =============================
/// Thread entry point
void ServerThread::run()
{
	QTcpSocket socket;
	socket.setSocketDescriptor( _socket );
	// say something
	qDebug("Incomming connection from %s", qPrintable( socket.peerAddress().toString() ) );

	try {
		// create server
		Server server( NULL );
		
		server.setSocket( & socket );

		server.processPackets();
	}
	catch( const GException& e )
	{
		qDebug("Autoserver: connection error: %s", qPrintable( e.getMessage() ) );
	}
}
